#include "nnsliteglobal.h"
#include "nnslitememory.h"

nnsliteObject nnsliteObjectCopy(const nnsliteObject* src)
{
	nnsliteObject newobj;
	newobj.id = src->id;
	newobj.size = src->size;
	newobj.data = nnsliteMAlloc(newobj.size);
	memcpy(newobj.data, src->data, newobj.size);
	return newobj;
}

NNSLITE_RET nnsliteObjectCopy2(nnsliteObject* dest, const nnsliteObject* src)
{
	if (dest->size < src->size || dest->data == NULL)
	{
		if (dest->data != NULL)
			nnsliteMFree(dest->data);
		dest->data = nnsliteMAlloc(src->size);
		dest->size = src->size;
		if (dest->data == NULL)
		{
			assert(false);
			return NNSLITE_RET_ERR_ALLOCATE_MEM;
		}
	}
	memcpy(dest->data, src->data, src->size);
	dest->id = src->id;
	return NNSLITE_RET_OK;
}


NNSLITE_RET nnsliteObjectInit(nnsliteObject* obj)
{
	obj->data = NULL;
	obj->id = 0;
	obj->size = 0;
	return NNSLITE_RET_OK;
}

NNSLITE_RET nnsliteObjectFree(nnsliteObject* obj)
{
	if (obj->data != NULL)
		nnsliteMFree(obj->data);
	obj->data = NULL;
	obj->id = 0;
	obj->size = 0;
	return NNSLITE_RET_OK;
}

